//资源文件加载器，确保canvas在图片资源加载完成后才进行渲染
import Resources from './Resources.js'

export default class {
  constructor() {
    this.map = new Map(Resources)
    for (let [key, value] of this.map) {
      // let image = new Image()
      let image = wx.createImage()
      image.src = value
      this.map.set(key, image)
    }
  }

  onLoaded(callback) {
    let count = 0
    for (let value of this.map.values()) {
      value.onload = () => {
        count++
        if (count >= this.map.size) {
          callback && callback(this.map)
        }
      }
    }
  }

  static create() {
    return new this()
  }
}
